package com.bjsxt;

import java.util.Comparator;
//comparator 接口是泛型类型 因为要比较student类，直接定义泛型为student
public class StudentComparator implements Comparator<Student> {

     //实现接口comparator
   //定义比效规则  正数:大，负数：小 0：相等
    /*@Override  //Object 要改为Student
    public int compare(Object o1, Object o2) {
        return 0;
    }*/
   @Override
   public int compare(Student o1, Student o2) {  //两个参数
       if(o1.getAge()>o2.getAge()){
            return 1;
       }
       if(o1.getAge()== o2.getAge()){
           return o1.getName().compareTo(o2.getName());
       }
       return -1;
   }
}

